﻿using System;
using System.Collections.Generic;

namespace OperationPlugins
{
    /// <summary>
    /// Provides information about a plugin.
    /// </summary>
    internal abstract class PluginInfo
    {
        private readonly List<OperationId> _operationFilters = new List<OperationId>();
        private readonly List<BranchId> _branchFilters = new List<BranchId>();

        /// <summary>
        /// Plugin type
        /// </summary>
        internal Type PluginType { set; get; }

        /// <summary>
        /// List of operation filters
        /// </summary>
        protected List<OperationId> OperationFilters
        {
            get { return _operationFilters; }
        }

        /// <summary>
        /// List of branch filters
        /// </summary>
        protected List<BranchId> BranchFilters
        {
            get { return _branchFilters; }
        }

        /// <summary>
        /// Checks if the plugin is valid for the specified operation.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <returns>true/false</returns>
        internal bool IsValidFor(OperationId operation)
        {
            if (OperationFilters.Count == 0 || OperationFilters.Contains(operation))
            {
                return true;
            }

            return false;
        }

        /// <summary>
        /// Checks if the plugin is valid for the specified branch.
        /// </summary>
        /// <param name="branch">The branch.</param>
        /// <returns></returns>
        internal bool IsValidFor(BranchId branch)
        {
            if (BranchFilters.Count == 0 || BranchFilters.Contains(branch))
            {
                return true;
            }

            return false;
        }

    }
}